302 Redirect - Intercepting Redirect response and query string - asp.net-core

I am looking to read the Redirect details in the middle ware (is there any other place?). Towards this I have created the required middleware, and the break point is hitting the code. However, unable to locate the Redirect details like path and the query string from the httpContext object. I'm been looking into this for the past hour or so, with no luck. Thanks in advance for your time.

It's in HttpContext.Response.Headers["location"]

Related

session being null when redirect to query string url in .net core

I'm setting url with query string when anyone hit such page which is only access after login. I set that controller name as query string and redirect to login page. everything working good till here. but when i login and using Response.Redirect(returnUrl); than it is converting my session null. here returnurl is coming as /Control/Index. if i simply redirect as return RedirectToAction("Index", "Control"); than it is working fine.
What can be the problem.
Working Good Redirection - RedirectToAction("Index", "Control");
Not Working Redirection - Response.Redirect("/Control/Index");
Your problem comes down to a question:
What is the difference between Response.Redirect() and RedirectToAction()?
Both are used to transfer request from one page to another. Both will give 302 status code. Both can be used for the same purpose, but the devil's in the details.
Response.Redirect (as well as Redirect() used with just URL) redirects a request to a new URL and specifies the new URL. RedirectToAction() terminates execution of the current request and starts execution of a new one using specified action and/or controller name.
RedirectToAction() keeps the old request with session. Response.Redirect() does not as it's out its scope. RedirectToAction() stays on the server to execute another request, while Response.Redirect() returns the response and then processes next request from scratch as a separate one.
So, is RedirectToAction() better? It's not better, it's just meant for different use case. For example, you can't redirect to different website with RedirectToAction() as it's out of scope of your local web application. You'd have to use Response.Redirect() while passing the URL to the desired webiste.
See this article explaining the differance in greater detail and illustrating round trips made for both methods. Notice that it does not exactly explain your problem as it shows difference between Response.Redirect() and Server.Transfer() from ASP.NET Web Pages, but the presented concepts taking place are very similar.

Yii2 url is to long so I receive a 403 code

Is there any setting for url limit in Yii 2?
Some of my urls are over 300 characters and I get a 403 Forbidden code;
http://website/servicii-de-proiectare-asistenta-tehnica-din-partea-proiectantului-pe-perioada-derularii-lucrarilor-si-executie-de-lucrari-pentru-proiectul-%E2%80%9Emodernizare-drumuri-comunale-dc----dc----si-dc---a-de-pe-raza-comunei-lunca-judetul-boto-ani%E2%80%9D-863506-switch.html
If I shorten the url, it works.
this is my urlmanager rule:
'<title:(.*)>-<id:([0-9]+)>-access-not-granted.html' => 'member/licitatii/access-not-granted',
I tried to find some information regarding this issue and surprisingly enough, I didn't found a thing regarding URL length permitted.
However, I found a Yii way to solve your issue: Short URL Yii extension presented here - http://www.yiiframework.com/extension/google-url-shortener/
Also, please read this documentation that better explains how Yii treats URL routs: http://www.larryullman.com/2013/02/18/understanding-routes-in-the-yii-framework/
I know this does not solve your problem directly, but hope it gets you somewhere!
L.E: Here you have the bitly extension for Short URL's: http://www.yiiframework.com/extension/bitly-url-shortener/
Keep on coding,
Ares.
Why would that rule apply to your URL? From what I can see your URL will never trigger that rule.
I do not think there is a limit with the string of the URL in Yii2, try deleting some of the first part of the string to test this. try with an url like
http://website/proiectul-%E2%80%9Emodernizare-drumuri-comunale-dc----dc----si-dc---a-de-pe-raza-comunei-lunca-judetul-boto-ani%E2%80%9D-863506-switch.html
You might have problems because you have diacritics in the URL, try without them.

Rewrite URL using DSAPI

I need to rewrite URL. i.e. when user send request for 'url1' we will do request to 'url2' ('url1' will not be changed in browser, users should not know anything about that). I've looked a bit around and did not find another solution but DSAPI filter. DSAPI can do what I need, however due to low experience I can't complete that task.
Can somebody suggest me what events should I look into? and what exactly should I do..
I was looking on those events: kFilterStartRequest, kFilterRawRequest or kFilterRewriteURL no success yet.
I've just complete my solution based of DSAPI, please read here how to rewrite URL using DSAPI.

How Can I Deal With Those Dead Links After Revamping My Web Site?

Couple of months ago, we revamped our web site. We adopted totally new site structure, specifically merged several pages into one. Everything looks charming.
However, there are lots of dead links which produce a large number of 404 errors.
So how can I do with it? If I leave it alone, could it bite back someday, say eating up my pr?
One basic option is using 301 redirect, however it is almost impossible considering the number of it.
So is there any workaround? Thanks for your considering!
301 is an excellent idea.
Consider you can take advantage of global configurations to map a group of pages. You don't necessary need to write one redirect for every 404.
For example, if you removed the http://example/foo folder, using Apache you can write the following configuration
RedirectMatch 301 ^/foo/(.*)$ http://example.org/
to catch all 404 generated from the removed folder.
Also, consider to redirect selectively. You can use Google Webmaster Tools to check which 404 URI are receiving the highest number inbound links and create a redirect configuration only for those.
Chances are the number of redirection rules you need to create will decrease drastically.
301 is definitely the correct route to go down to preserve your page rank.
Alternatively, you could catch 404 errors and redirect either to a "This content has moved" type page, or your home page. If you do this I would still recommend cherry picking busy pages and important content and setting up 301s for these - then you can preserve PR on your most important content, and deal gracefully with the rest of the dead links...
I agree with the other posts - using mod_rewrite you can remap URLs and return 301s. Note - it's possible to call an external program or database with mod_rewrite - so there's a lot you can do there.
If your new and old site don't follow any remapable pattern, then I suggest you make your 404 page as useful as possible. Google has a widget which will suggest the page the user is probably looking for. This works well once Google has spidered your new site.
Along with the other 301 suggestions, you could also split the requested url string into a search string routing to your default search page (if you have one) passing those parameters automatically to the search.
For example, if someone tries to visit http://example.com/2009/01/new-years-was-a-blast, this would route to your search page and automatically search for "new years was a blast" returning the best result for those key words and hopefully your most relevant article.

.htaccess - route to selected desination but change browser url

Problem:
I'd like to accept the original request. Say its, /IWantToGoHere/index.php
but I want to return to the browser, /GoHere/index.php
To be clear:
I actually want to send the original request location down to the script requested, however, I want to return the user a browser URL to another destination.
Code:
RewriteEngine on
RewriteRule ^(.*)IWantToGoHere\/\.php$ GoHere/index.php [NC,C]
RewriteRule ^GoHere/index.php$ GoHere/index.php [R,NC]
Notes:
I realize the code above doesn't work. I've tried a number of different calls. I spent umpteen hours yesterday trying every clever solution I could pull out of my limited mod_rewrite knowledge bank. Based on my understanding of mod_rewrite, I don't think it's do able. I understand its not what the preprocessed was designed to do. At least not from anything I could find on the Apache web site. I've been told that if I could dream it up, that it could be done:) I was wondering if anyone had and ideas how to get it to work.
Why would you want to do that?:
Because I do. No really, I want the URL returned to the user for further processing.
weez
If I understand the question correctly, to accomplish this you'll need to send a header from /IWantToGoHere/index.php that redirects to /GoHere/index.php once the script is finished executing. That is, if you want Apache to still call IWantToGoHere but return to GoHere. So at the end of processing for IWantToGoHere script something like this:
header('Location: /GoHere/Index.php');
Which will redirect correctly.