how to pass querystring in friendly url in asp.net web application - asp.net

Hope this is the best place to put this question.
I am working on a web application.Where any user can check detail of other user by a link.
currently this is the link for test
http://www.contractgenies.com/Snapshotprofile.aspx?ViewRef=test09last099826
it is working fine but
Problem :
I want to show this as :
http://www.contractgenies.com/test09last099826
without query string or page name.
Is this possible or not please let me know.

You can use UrlRewriting mechanism to achieve this job.
URL Rewriting Module
If you are going to use ASP.Net MVC then use routing mechanism.
Routing Mechanism ASP.Net MVC

Related

Static pages in ASP.NET MVC

Suppose that your ASP.NET MVC website contains a handful of dynamic pages and a big amount of static pages that of course need the Login & Register link on the top right corner. How do you handle this?
We have converted the HTML pages to ASPX and introduced the ASP.NET code to display the user name but I am not sure that it's the best approach. In addition we needed to move static pages to a different folder to avoid collision with MVC routing.
Is this the best that can be done?
Thanks.
ASP.NET MVC and Web Forms can live together with no problem. If your approach is working out for you then it should be fine.
Also see the below article. It might help :
Integrating ASP.NET MVC 3 into existing upgraded ASP.NET 4 Web Forms applications
http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx
I believe as long you implement Donut caching within the ASP.Net pages you can get similar performance as static html pages.
If you use IIS Form Athentication for your site static content can be accessed only if the user is authenticated, so you can mantain HTML files and do not convert them in ASPX, but you need to add some javascript to hide the login link and display username (you can check the auth cookie of IIS or create your custom cookie).
Have you considered some client side script that loads the username/password section you need?
You could have it load a view and inject it into a div. Then you have a single point to maintain for all the static content.

URL Rewriting in IIS 6 Using ISAPI_Rewrite 3

I am running into an issue where I am trying to implement SEO friendly links in an ASP.Net 3.5 application with IIS6. The issue is that when I try to use a url like "www.text.com/about/" it isn't directed to the ASP.Net pipeline, so I am unable to route the request to the correct physical aspx file. With ISAPI_Rewrite I know I can redirect a request to the specific page, but is there a way to have a request sent to the ASP.Net pipeline, so I can manipulate the request using the built-in routing engine. Any help is appreciated.
Wade
Wade ,
You can either implement urlmodule which extents ihttpmodule.
or you can implement httphandler , You need to make this entry in httphandler section of web.config , so that each request comes to .net handler , you can customize your path there and rewrite the url
let me know if you need any help.
as sample example
http://www.aspnettutorials.com/tutorials/advanced/httphandler-aspnet2-csharp.aspx
let me know if you need any help , i implemented recently
I found the technet article on how to route wildcard traffic to the asp.net pipeline. Here is the link - http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true.

How to create a blog in ASP.NET and not ASP.NET MVC

I have created a blog application with ASP.NET MVC and MSSQL. I must say, i really enjoyed the process of creating an application with ASP.NET MVC. Clean URLS(with URL routing), No view States and so on.
BUT i was wondering how would this would have been done if i choose web-form style coding? will the aspx would be created in the fly as i create a article.(take this url for ex: http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx) though the URL is not clean but still makes sense. if yes then what about its corresponding cs file? if no how is the URL so clean?
Would be great if someone throw some light on how it is done in ASP.NET.
Thank you, Faraaz.
If your using .NET 4, you can make use of MapPageRoute to accomplish the clean URL's with regular Web Forms.
routes.MapPageRoute("MySuperCleanRoute", "some/clean/url", "~/ActualPage.aspx");
With the addition of MapPageRoute, you no longer have the feeling "I should use ASP.NET MVC because i want clean URL's".
Choose ASP.NET MVC if you like the pattern. If your used to Web Forms, use it - and use MapPageRoute to achieve clean URL's (or use a URL Rewriting module if <= .NET 4)
A blog in ASP .NET would have been done in much the same way. The idea is to use one file and URL rewriting. IIS7 has URL rewriting built in but for IIS6 you can use something like ISAPI_Rewrite to handle .htaccess style files (which is what Apache uses).
ASP .NET MVC handles all this for you in its routing but you can do it yourself using a URL rewriting tool. The difference is that for MVC, the application handles the rewriting but ISAPI_Rewrite, IIS Rewriting are done by the server. This can change a URL like http://mysite.com/something/other to http://mysite.com/file.asp?p1=something&p2=other.
The second link is only internal to the server (it doesn't actually change the URL in the user's address bar). In the case of a URL like on Scott's blog, you could store the 'announcing-nupack-asp...' bit in a database as part of the article row so your blog article page has something to look for. The files don't actually exist on the server but the rewriting passes all requests to an existing file with parameters.
Note that this technique is common for lots of different sites - not just blogs. Notice the Stack Overflow URL, Twitter URLs, etc.
MSDN has an old article on URL Rewriting in ASP .NET, along with some examples of filters you can use.
See IIS URL Rewrite Module
You can use the URL Rewriting that is in asp.net MVC with WebForms if you are using .Net Framework 3.5 SP1 (if you don't have access to .Net 4)
Here's an MSDN magazine article explaning...

ASP.NET Routing

I have a small task to do, and figured it would be better to start here than doing it wrong then coming here again.
I need to replace my URLs with a more friendly format as the following:
Current: www.MySite.com/default.aspx?userID=XX
I want it the users to type : www.MySite.com/user/(UserName)
Also, Current: www.MySite.com/default.aspx?userID=XX&ref#XX
I want the users to type: www.MySite.com/user/(UserName)/ref#{refno}
Thanks in advance
PS: I do not want to use Asp.net MVC.
You can use the MVC Routing Feature without using MVC, as it's a separate component built on top of ASP.net.
There is an article on 4GuysFromRolla about this.
You can use routing in Webforms:
Using ASP.NET Routing Without ASP.NET MVC
If you can, I'd just use IIS7 URL Rewriting for that. Your mapping configuration can go in your web.config, and you wouldn't have to change your application at all.
Friendly URL tutorial
IIS7 Rewriting and Web Forms

Displaying the current authenticated Sharepoint user from an asp.net Page Viewer Web Part

I am creating a standalone asp.net page that needs to be embedded into a sharepoint site using the Page Viewer Web Part. The asp.net page is published to the same server on a different port, giving me the URL to embed.
The requirement is that after a user is authenticated using Sharepoint authentication, they navigate to a page containing the asp.net web part for more options.
What I need to do from this asp.net page is query Sharepoint for the currently authenticated username, then display this on the page from the asp.net code.
This all works fine when I debug the application from VS, but when published and displayed though Sharepoint, I always get NULL as the user.
Any suggestions on the best way to get this to work would be much appreciated.
If you want to retrieve the currently authenticated user from the SharePoint context, you need to remain within the SharePoint context. This means hosting your custom web application within SharePoint (see http://msdn.microsoft.com/en-us/library/cc297200.aspx). Then from your custom application reference Microsoft.SharePoint and use the SPContext object to retrieve the user name. For example:
SPContext.Current.Web.CurrentUser.LoginName
You can still use the Page Viewer Web Part to reference the URL of the site, now located within the SharePoint context.
Thanks heaps for the answers!
Turns out that as long as the asp.net page is using the same URL and port as the Sharepoint site, authentication works across both sites.
The solution is to use a Virtual Directory inside of the sharepoint site and install the asp.net page there.
When it works in debug, is that being used in SharePoint?
Your page and the Sharepoint site might as well be on different servers as far as authentication is concerned -- in order to get the information over you might need to pass it via the QueryString from the webpart if you can -- or you might need to make your own webpart to do this (just put an IFRAME in the part with the src set to your page with the QueryString passing the username).
It does seem that this would be a security issue if you use the name for anything though -- if you are just displaying it, then it's probably fine.
If you actually need to be authenticated, you might need to add authentication into the web.config of the site hosting your standalone page.
edit: I think you'd have better luck putting your page on the same port and server as SharePoint.
I suspect you will have a hard time specifically querying SharePoint for the currently authenticated username. I can't think of a way to easily access the SharePoint context from a separate web application like you are describing.
I don't know what kind of authentication scheme you are using, but you may want to consider using Kerberos, as I've found that it can make these kinds of scenarios a little easier by allowing for delegation and passing credentials from application to application or server to server.

Resources