I want to hide part of the address in the browser toolbar in asp.net.
For example, if it's http://mysite.com/News/Shownews.aspx?ID=-1&Num=20, it should change to http://mysite.com/ on every page.
I visit some websites that do exactly like this. Can anybody help me?
You probably want UrlRewrite.
Or, you can use asp.net mvc, it has routing feature.
No idea why you would do such a thing, but some hacky solution comes to mind:
http://mysite.com/News/Shownews.aspx?ID=-1&Num=20 will respond with a redirect to http://mysite.com/ and stashes whatever information is necessary in cookie/session state/... (like ie. the complete original request URL)
The controller handling http://mysite.com/ grabs the state and renders the appropriate output
Of course this might introduce some race conditions dependent on the exact method used to store the relevant state.
All in all that whole undertaking is a pretty bad idea thinking of principles like REST...but since you asked for it...
Yep, URL rewriting is what you're looking for most likely: http://msdn.microsoft.com/en-us/library/ms972974.aspx is a broad overview of the topic.
Related
I am building my own GridView in an ASP.NET project
I am drawing out my plans and I was wondering what the best solution is to a simple problem, paging and sorting.
The fast and easy way is using submit buttons (or similar) and POSTING the form back. That's also how the ASP.NET gridview works.
pro:
less overhead
con:
backbuttons
The second method is using links and the URL with GET requests.
pro:
backbuttons work just fine
direct link to certain position
con:
less reusable because of the dependence on url
The third method is AJAX
pro:
little overhead
con:
harder to implement
What design/solution would you pick and why?
Am i overlooking some pros and cons?
I add some extra comments to think about.
-The second method is using links and the URL with GET requests.
This is the one that you need to use, if your need web spiders (google) knows all the pages of your site, and be SEO friendly. This method have the problem that you can not have viewstate and each time you must render the page that you see on the url parameters with out knowing anything else.
With this case you probably have more problems if you wish to make edit on one line
-The fast and easy way is using submit buttons (or similar) and POSTING the form back
This is the method if you won to have many functionality on code behind because with the post back you have all the previous action that you have done, and the viewstate is working and can be used for that. Is not SEO friendly and if you like to make it you need extra code to write on the url just the page that you are now and need to land.
-The third method is AJAX
This is the method that must co-exist with the previous and not alone for the case that the browser fails to run javascript for any reason. If you do not care about that, the rest is that this method is also not SEO friendly and you need to make it, is cool, modern, and is a must for modern site, but if you going to make difficult things then you may end up with many issues that must be solved.
To summarize:
More than show data ? Post Request : Get Request ; // ToDo: make it ajax
ASP.NET, web form model.
Is there any sample code/site that demonstrate a couple samples for regular website patterns/ templates? Like if I want to use tab to switch between different pages, should I put the code in a single page or in different page, and treat each tab as a page.
Or if in a search page (just a single search bar and button), should I display my result panel in same page using dynamically enable the result panel, or just to another page?
I want to find a general design pattern/ template. Please advise, thanks.
I don't know if this answer will be helpful to you or not. Correct me if I am wrong.
You are specifying demonstration about web designing. It seems the functionality you want is clearly saying to choose from weather you want to use AJAX or not. I suggest why don't you use jQuery Framework for all this functionality.
I would give this a read and consider what best fits your application and your programming style, no one size fits all with paterns.
http://msdn.microsoft.com/en-us/magazine/dd252940.aspx
After you have a general idea, head over to google.com and look for the patterns that catch your eye for simple tutorials
Edit:
For the specific question about whether you should modularize your code. The answer is almost always yes. If you think there is a chance that the component will be used somewhere else then doing this a head of time can save you a lot of headache later. This practice also makes maintaining a lot easier because it gives a clear scope of what could be causing a bug. Instead of having to look threw an entire page of unrelated code for things changing state unexpectedly in the page life cycle.
I have a ASP.NET 3.5 webforms project I have enabled routing over.
I also have in the project a number of controls doing different things based on what page they are currently being shown in. It would seem that the most straightforward way to control this different behavior is to discover which route was used to load the page and then do things according to that.
However, I can't seem to find a way to discover the route bar looking at the actual request URL and running a regex over it which isn't great. Does anyone know a way to look it up some other way?
Update: there still doesn't appear to be a way to do this in ASP.NET 4.0. Hopefully someone else has figured this out?
It looks like Phil Haack has answered this question in a blog post on his site: http://haacked.com/archive/2010/11/28/getting-the-route-name-for-a-route.aspx
In a .NET 4 webforms app, I used this to determine the route definition.
string myOperation =
((System.Web.Routing.Route)(Page.RouteData.Route)).Url;
//string has value "Stop" or "Start"
Let's say your routes are like so:
routes.MapPageRoute("StopEmailAlerts",
"Stop/{SomeToken}",
"~/Emailing.aspx", false);
routes.MapPageRoute("SendEmailAlerts",
"Start/{SomeToken}",
"~/Emailing.aspx", false);
I posted a couple of simple extension methods you can use to get/set the route name on this post. Seems simpler (to me) than Haack's solution.
Quick question.
There is a legacy website (that is not under my control and cannot be modified), that gives users a form to fill in data and then the user 'submits' the form for processing. There is virtually no error checking on this form, and very little help for the user (i.e. it was very poorly designed about 12 years ago and hasn't been updated since).
None-the-less, the back-end of this application performs a critical function.
My question is, is it possible (without having any ability to modify the legacy website), to write my own new front-end in asp.net (with proper pre-submit validation) living on a different server & domain, and then simulate the 'submit' to another webserver as long as I reproduce the form/data that is being sent?
The key question here I guess, is it possible to submit a form produce on one website, to another, and can this be done with ANY changes to the legacy site?
Comments appreciated.
The key question here I guess, is it possible to submit a form produce on one website, to another, and can this be done with ANY changes to the legacy site?
Yes, I've done this before - provided that the target site doesn't do any referer checking. A POST request is a POST request, no matter where it originates from.
You just need to make sure that all the fields are exactly the same in your request as they would be coming from the original page, i.e. - same field names, same encoding etc.
The short answer is "yes", the long answer is "it depends". The basics of HTML and HTTP allow for it, but without knowing a little more about the implementation of the legacy site you can't know for sure that it will work.
In theory you just need to make sure that the name of the fields are the same and set the target of the form to the legacy site's page URL.
In practice the legacy site could be doing various things that make it difficult or impossible to achieve (it could require cookies set correctly or hold internal state for example).
The best thing would be just to try it. It shouldn't take long just to mock up the basic fields and post the form to see if it works. Once you know it works then you can worry about adding your extra validation etc
Beware that if the existing site is authenticating users you'll need to find a way to also collect and pass that info along. Otherwise, though, Phill's point is spot-on.
This sounds like a "why would you do that?" sort of question, but here goes..
I have a very simple ASP.NET page which simply renders out a one column grid of about 10 rows with paging.
At the moment, I need (due to some technical restrictions) to essentially host the ASP.NET page within an IFRAME on a basic HTML page. It works of course, although I wonder if there is a better way?
For some reason I am thinking something like silverlight (which I might end up using) being a container.. or some other ActiveX type control..
Hope this explains enough?
Thanks in advance!
You're right, this is pretty much a "why would you do that" type of thing. However, we all know that you don't always have control over what you would like to do thanks to managers who don't know jack about developing websites, etc :) as I've been in a similar position and been forced to do almost exactly the same thing.
Anyways, I believe the way you are doing it is about the simplest way to do it. The only thing you might want to keep an eye on (I don't know if you are running from separate domains, as the question doesn't specify) is cross-domain scripting. For example, if your ASP.NET page is at www.myaspdomain.com and your HTML page is at www.myhtmldomain.com, cross-domain scripting, or scripting between the IFRAME and the ASP.NET page can cause some interesting bugs (features?) because of the security holes that such scripting opens up and has thus mostly been blocked nowadays.
You might be able to use XmlHttpRequest to fetch the contents on ASP.NET page to an HTML element.