Custom 404 Redirect For A Site With URL Rewriting?
Sep 1, 2010
In my site, I have used IIS7's URL rewrite module to redirect URLs like http://mysite.com/File.aspx?Name=SomeName into http://mysite.com/SomeName.
It appears that IIS7 has created a corresponding rule check, so that any URL of the sort http://mysite.com/SomeURL is redirected to File.aspx. This is fine in most cases, when the URL is correctly rewritten.
The problem is that in some cases, the file no longer exists - http://mysite.com/SomeName2 will still get redirected to http://mysite.com/File.aspx?Name=SomeName2.
I want to show a custom 404 error page for this URL - how do I trigger the 404 error in global.asax (I have set application error logging and handling in global.asax)? The below code doesn't work.
Response.Status = "404 Not Found"
Response.AddHeader("Location", "http://mysite.com/Invalid-File.aspx?" & Request.QueryString.ToString)
View 3 Replies
Similar Messages:
Feb 18, 2010
In answering another persons question here on SO, I discovered that there is a small "bug" in my global redirect code.I have wired up a Global class to an HttpModule. It's job is to detect "http:/www." in the URL and redirect the user to the NON www. version
Protected Sub OnBeginRequest(ByVal sender As Object, ByVal e As EventArgs)
'Force Removal of WWW
Dim application As HttpApplication = TryCast(sender, HttpApplication)
[code]....
when it redirect a page http://www.example.com/AboutUs, the goal is to have it go to http://example.com/AboutUs (the rewritten page) but instead it's going to http://example.com/Default.aspx?Slug=AboutUs (the original page).I tried doing a bit of a hack by changing
Dim newUrl As [String] = UrlRegex.Replace(url.ToString(), [String].Format("{0}://", url.Scheme))
application.Context.Response.Status = "301 Moved Permanently"
application.Context.Response.AddHeader("Location", newUrl.Replace("Default.aspx", ""))
to
Dim newUrl As [String] = UrlRegex.Replace(url.ToString(), [String].Format("{0}://", url.Scheme))
newUrl = newUrl.Replace("Default.aspx?Slug=", "")
newUrl = newUrl.Replace("Default.aspx", "")
application.Context.Response.Status = "301 Moved Permanently"
application.Context.Response.AddHeader("Location", newUrl)
not something I want to do anyways since it's a hack, but it didn't work anyways.
View 4 Replies
Mar 1, 2011
i want to integrate simple url rewriting in my site. It is dynamic website that get contents from the Link My link is always like sitename.com/default.aspx?param1=1¶n2=hello¶m3=test I have only one page in this site. how to implement URL rewrite in this file. I use some demos but unable to do this.
View 1 Replies
Sep 11, 2010
I am creating a dynamic website in asp.net based on content fetching from MSSQL DB. What I want to do is : everycontent has its own link/url based on contentId-Title. How can I do this?
Example:
Table has :
ID :1
Title : Mytitle
Description :This is description
Extension : .html
Url :
Now, I need to show the all results in a datagrid with title link as:
Title : mytitle => Now whenever anybody clicks on it it will resolve in the form of : "/1-mytitle.html"
So, formula to create url is : ID-Title Extention
for instance above will generate as :
<a href="/1-mytitle.html">MyTitle</a>
View 2 Replies
Jul 9, 2010
I have developed one site the name call [URL]. And I have created one more domain called [URL]. In both the domain I have uploaded same fields to display in browser the main functionality in this when the user can visit in india for ex : [URL] it ll automatically redirected to [URL] as well if the user other than india just open the [URL] only. How can I achieve this no need of third party link or tools. How can I implement this.
View 3 Replies
Mar 31, 2010
I have two sites that are app1 and app2. If a user requests a resource in app2, in order to authenticate, I like to redirect to the login page which is in app1. Once authenticated over there, return back to app2.
View 1 Replies
Apr 10, 2010
I am trying to implement URL rewriting technique in my Web application.I have found some articles on net 2 rewrite URL. But i m not able to understand. tell me any API or DLL which will take care of all url rewriting techniques in my Web applications.
I have heard something abt UrlRewriter.ddl . But i have not used it yet. provide me the easiest way to do that. If any sample application is there then it will be better ti understand
View 4 Replies
Jan 29, 2011
I picked up a new-to-me client who had a site built in ASP.net (which I do not host).I converted the site to PHP, which worked fine.I want to set up redirects for all the pages he had in the old site (it was a small site, so there was only 8 pages).As an example, the ASP.net url for the Contact page was www.domain.com/Contact - it is now www.domain.com/Contact.php (and so on).
For 301 redirects from one PHP page to another I normally use the .htaccess file:
Options +FollowSymlinks
RewriteEngine on
#custom redirects
rewriterule OldPage.php http://www.domain.com/NewPage.php [R=301,L]
#end custom redirects
What can I do to redirect these ASP.net pages to the new PHP pages?They are all static pages with no dynamic content.
View 1 Replies
Aug 12, 2010
i have one website (asp.net static pages and one login page) hosted on one server (x hoster) ..in that web site i have login page... i have another another server where i hosted the database and my asp.net application...( y hoter)the database is same for both applications...how to redirect my login members from website 1 to website 2..i am maintaing some sessions on website1 , when credentials checked..once the login successfully i need to redirect the member to my second website..
View 2 Replies
Jan 21, 2010
After button click i would like to redirect to other site but without blink. Is it possible with updatepanel?
This is my main page:
[Code]....
Redirect:
[Code]....
on other page i have only label with text.
View 6 Replies
Apr 27, 2010
I have a home server running at home and I want to grant family members access to certain private websites.
Reese with password 1234 should type in his url like this: http://www.my.my/reese1234 and get redirected to where I want him to be redirected to.
Can I use a webservice for this? If yes, how do I start? (I use ASP.NET and C#) Or is there a better option which will also improve performance? Of course I want to redirect with the least amount of performance so other processes will be on max bandwidth.
View 2 Replies
Dec 9, 2010
I have a requirement that whenever a user logs onto a website using forms based authentication [FBA] that the site checks whether they have a related domain NT user record. There will be a matching lookup table between the ASPNETDB membership database and related domain accounts for users.Whenever an FBA user logs in and a related domain account is located then the member should be redirected to an alternative site / URL which is Windows NT authenticated rather than FBA. Before transferring them I would like to be able to pre authenticate them on the windows domain rather than an additional NT Login dialog box coming up and asking them to enter the related NT credentials.Is it possible to programatically preauthenticate using NT credentials before redirecting a user to an NT authenticated site?Note: This isn't technically a single sign on style scenario. The FBA / NT authenticated sites are not related other than the relationship between the original FBA credentials and the NT credentials lookup.
View 1 Replies
Oct 1, 2010
I have 2 sites, one the main product site the other a secure site featuring the basket and checkout processes.
When a user clicks "add item to basket" I am creating a basket in a database and then adding the items to the basket. The theory was then to store the id from the database for the basket (the basketid) in a cookie, redirect the user to secure site, use the basket id from the cookie and display the contents in the basket.
However I am having trouble getting the secure site to use the same cookie. When I redirect the users to the secure site, the basket appears empty. I need to go back to the main site and then back to secure before the cookie appears.
Here is the code for the cookie
[Code]....
And then on the secure site this is how it gets the basket ID from the cookie
[Code]....
But like I say it's having problems. I've tried replacing the cookies with session variables as well but it didn't work.
View 6 Replies
Nov 10, 2010
I have developed .net web application. When i change the page name(Which is not exist) in URL, it throws following error msg. I could not redirect the error page for respected error no(401.2..) Through IIS Admin and web config. Could anybody give appropriate solution. It is urgent. Access is denied. Description:
An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL. Error message 401.2.: You do not have permission to view this directory or page using the credentials you supplied. Version Information: Microsoft .NET Framework Version:1.1.4322.2470; ASP.NET Version:1.1.4322.2470
View 3 Replies
Jan 5, 2010
I have created a custom error page to redirect whenever any error occurs. I made the following changes to the web.config file
<customErrors mode="On">
<error statusCode="403" redirect="~/Error.aspx" />
<error statusCode="404" redirect="~/Error.aspx" />
</customErrors>
Suppose my url is in the following way: http://MyTestSite/Posts/Post1.aspx
If I remove the .aspx at the end manually then it is not displaying my customm error page instead it is dispalying default 404 error page : Page cannot be found.
Also, if I give http://MyTestSite/Posts the same 404 error message is displaying. Even the Application_Error event in global.aspx is unable to handle this error.
How can I redirect these type of cases to my custom error Page? Do I need to make any changes in IIS default errors or can I able to acheive only using web.config?
View 14 Replies
Feb 24, 2011
I am using a custom event in third party library for my asp.net project. When the event happens, I need to redirect to another page. Problem is that since it is custom event, Server.Transfer or Response.Redirect can't be used (I tried but got "response is not available in this context"). So I think best way would be to trigger post back in the event and redirect in page_load event on appropriate conditions. Is this right approach or is there any better idea? And, how can I trigger postback?
View 2 Replies
Jul 19, 2010
I have custom errors set in the web config file as follows:
<customErrors mode="RemoteOnly" defaultRedirect="GenericError.aspx" />
Fine and dandy... I like that mode="RemoteOnly" facilitates development...
For unhandled exceptions, I have in global.asax:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect("GenericError.aspx")
End Sub
However, unhandled exceptions are going to the generic error page instead of the informative yellow screen of death preferred by developers. I can comment out the redirect in global.asax, but then I need to remember to change it for the production environment. Is there a way I can check in Application_Error whether I am remote or not to determine whether to redirect?
View 2 Replies
Dec 1, 2010
i have developed a production site in godaddy server.Now i want to display a custom error page if there is any error occurs in the site.i have made following changes in the web.config file ,
<customErrors mode="On" defaultRedirect="/Areas/User/Views/Shared/Error">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="/Areas/User/Views/Shared/Error" />
</customErrors>
But now if error occurs the server will display his default error page for 404 page.Now i want to display my customised error page.Please tell me the entire steps to implement this in asp.net mvc 2.0.i,e is there any coding i have to write in then controllers or in the global.asax.
View 1 Replies
Sep 25, 2010
I created a custom membership provider for an MVC2 site.My web.config has this:
<membership defaultProvider="MyProvider">
<providers>
<clear/> [code]....
This value, MembershipService.MinPasswordLength, is zero (0). Obviously, this is coming from my class. I can't have a set because the abstract class has this as a read-only property.Why doesn't the MembershipProvider read this value from the Web.Config? What am I missing?
View 7 Replies
Mar 18, 2010
I'm using a custom sqlsitemapprovider to get my site hierarchy out of the database and display my navigation. Now, I have the following main (parent) nodes:
Home - Products - News. What I want to achieve is this, suppose you click on products then a subnavigation appears like this:
productGroup1,productGroup2, productGroup3.
But when you click products, no selection was made from the subnavigation, how would I achieve that if someone clicks on products, the
first product with content from the first productGroup1 shows up?
To visualize this: I click on Products -> Subnavigaton gets rendered -> PG1 - PG2 - PG3 -> page displays product1 of PG1
Is there as build in manner to accomplish this or how would one create a method to make this work?
P.S.:For my navigation, I'm not using any build in navigation controls, I'm rendering my menu as an html unordered list e.g: <ul><li></li></ul>
View 1 Replies
Oct 22, 2010
i have uploaded my site [URL] it it working properly on local machine but when i uploaded on server i am facing 1 error on button clik of any form. there are two ages career and contact whenever i submit this data by clicking button i get this error. Server Error in '/' Application. Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
[Code]....
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
[Code]....
View 3 Replies
Jun 3, 2010
Say I have a class that wraps the Controller class:
public class MyController : Controller
{
public string SomeProperty {get;set;}
public override void OnActionExecuting(...)
{
SomeProperty = "hello";
}
}
Now in my site.master, I want to have access to the SomeProperty that I just set. How can I do this?
View 2 Replies
Nov 28, 2010
When I have a HttpHandler class in C#/ASP.NET mapped to a file extension in IIS any file with that extension fails to download/display in web browsers (it's downloaded as a 0-byte file in some browsers and nothing at all in other browsers). After removing the application mapping for the HttpHandler in IIS so it doesn't call the IHttpHandler class in C#, the web browser downloads the file successfully.
This was tested with an IHttpHandler class in C# that has an empty ProcessRequest method.
View 2 Replies
Aug 3, 2010
I am facing problem in to redirect my site from http://example.net to http://www.example.net
When the user can enter the site name in address bar like http://example.net how can i automatically redirected to http://www.example.net
I am trying to change the properties in iis but it doesnot work.
how can i acheive this
View 3 Replies
Oct 11, 2010
I am trying to use the Application_Error to redirect the user to a custom error page. I know I could use the web.config to do this, but let's assume for now that this is not a desirable path to take.
Initially, I tried to do a Response.Redirect to perform this, however, there seem to be occasions where the current http context does not define the response object. So, I attempted to perform a check to make sure that the response object is not null prior to attempting the redirection, and if it is not defined, perform a Server.Transfer instead.
What happens is that in most cases, the Redirect causes the browser to some generic "friendlyish" error page rather than the requested error page.
So then I tried using Server.Transfer exclusively, and this worked well for most cases, however, sometimes the transfer didn't seem to take in the browser. Changing it back to a redirect in these cases solved that problem, but reintroduced the issue where the errors previously being captured and transferred now were being redirected.
What I surmised from this is that in certain contexts where the Application_Error method is trapped, it is necessary to use Server.Transfer in redirection, whereas in others, it is necessary to use Response.Redirect. The question then became twofold: (a) When is one necessary and when is the other? and (b) What available information can I poll to tell me when a given condition exists.
After much searching, I cannot find a reasonable answer to this question. So I began to trap errors and examine the HttpContext object for some indicator. One thing that I was looking for is the reason why if even with a defined Response in the current context does a redirect fail. The only thing that stood out is that even though a Response object may exist, the Session data could be absent. I added the case to check whether the Session data was null and perform a Transfer in this case and it
seems to be handling it properly.
I emphasize "seems to be handling it properly" because no documentation I've been able to find confirms either the problem I am having or whether this is an appropriate strategy for solving it.
I guess the question is, am I on the right track here or is the null Session object just a red herring, indicative of nothing relevant. Here's the check I have set up for reference.
[Code]....
View 2 Replies