In an ASP.Net MVC 1.0 applicati0n, is it possible to access the application settings (MyProject.Properties.Settings.Default.*) from inside my View (aspx page)?
I've tried but the intellisense and compiler don't like it. It says that it is inaccesible due to the protection level.
I had a similar issue to Saajid Ismail where my settings were in the namespace.Properties.Settings.Default.Setting they were there as they are strongly typed..
To make them accessible I simply had to change the access modifier
Your View should only be responsible for rendering data given to it by the Controller. It's responsibility is for layout. So I would recommend passing the Application data to the view from within your Controller action.
Having said that, the technical answer to your question is that ViewPage derives from Page, so you can simply do this:
<%= Context.Application["setting"] %>
But again, I don't recommend it.
Related
I'd like to let my user add HTML to an entry in a SQL Server table using the CMS, but I keep getting the warning:
System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (ctl00$MainContent$TextBox2="<p>We...
What is the best way to allow HTML to be added to my CMS?
Many thanks
You can enable/disable request validation on a per control, per page, or on application level.
See http://www.asp.net/learn/whitepapers/request-validation for more info.
Be aware that if you're using asp.net 4.0 you might have to set the requestValidationMode as well (see ValidateRequest="false" doesn't work in Asp.Net 4)
ASP.NET automatically tests forms for input of potentially dangerous characters (pretty much anything HTML...). To get around this you can ValidateRequest="false" at either the page or app level (in web.config), but then you will need to manually clean the HTML yourself to ensure that no malicious code is injected. The best article on code cleaning I've seen is http://wonko.com/post/html-escaping .
I'm looking for guidelines for how to best implement web page navigation logic for a Spring based web application. For example: I have a web page 'C' where if I click ok, I want flow to return to page 'A' if that was the previous page, or page 'B' if that was the previous page. I am currently using hidden fields on a page to track from which page I arrived...but I think there must be a better way...
You can use flash scope bean for saving the view Url from which you are redirected.
You can read about flash scope from this page:
http://blog.smartkey.co.uk/2011/01/implementing-flash-scope-in-java-web-applications/
See me response from this post. it Explains how to implement Flash Scope in SPring MVC environment.
Spring MVC custom scope bean
with this scope you can alway retrieve the URL form which you will redirected and then build link form the value retrieved.
Hope it helps.
My suggestion would be to use Spring Web Flow (http://www.springsource.org/webflow).
It's intended to do exactly what you want. Control the flows between pages.
I start using it a couple of month ago and I love it.
How common usage are Page Methods in ASP.NET 4?
I would like an example of how it's used (not a code sample).
I don't know about how common, but check out this example: http://aspalliance.com/1922_PageMethods_In_ASPNET_AJAX.all
Use page methods if you don't want to publicly expose a web service, and creating a web method that's specifically only to that page, IMHO. So for instance, I need web service features for one page only, that's when I create a page method. If I need something reusable in two pages, but don't want to publically expose it, I create a helper and the web method wraps the helper.
Otherwise, if you are looking to create a dynamic web site and share information, go with a traditional ASMX or WCF service.
HTH.
In your ASPX file you'll need this line.
<asp:ScriptManager ID="ScriptManager" runat="server" EnablePageMethods="true" />
In your code behind define a method marked as a WebMethod.
[WebMethod]
public static void MyMethod()
{
//code.....
Then to call that method in JavaScript.
PageMethods.SendForm(SuccessCallBack, FailureCallBack);
There are more advanced examples out there - just Google it.
I don't know about usage, but this is a very basic and clear example.
HI,
I have a ASP.NET webiste I created from craft and it now look a big mess. I want to reorganize this but don't know the good way to do it. Some first look well but later cause trouble with master page, image path...
Now I'm thinking of 2 ways:
Using UrlWriter: but it seems lead to a bulk of path rewrite and usually lead to Resource not found or something
Using a page as main entry and using Server.Tranfer to pull the right page content, despite of its location
Which is better? Do you have another method?
Please help!
There's another approach, System.Web.Routing, added in ASP.NET 3.5 SP1. Basically, you implement the IRouteHandler interface and manually route the request to an appropriate handler.
This is how ASP.NET MVC handles request routing. There's a guide here that uses it for Web forms.
By the way, consider looking at ASP.NET MVC and check if it's appropriate for your situation.
Mentioned stackoverflow only as an example, but if you look above the URL for ask is
http://stackoverflow.com/questions/ask
which means /ask is a subdirectory, but they also do this for the specific question pages. How do you code this in .NET?
Not a code question as much as a technique. I know this is great for SEO, but how do you create a site so that every "page" is its own directory? Dynamically.
Do you have a template or a hidden redirect???
How?? :)
It's termed URL rewriting:
Url Rewriting with ASP.NET
MSDN: URL Rewriting in ASP.NET
EDIT: As #Justice points out, StackOverflow uses Routing.
StackOverflow uses something called Routing, which comes with .NET 3.5 SP1. Routing is a popular feature of a number of MVC frameworks, such as ASP.NET MVC, Ruby on Rails, and a number of Python and PHP frameworks.
Stack Overflow was built using ASP.NET MVC which uses a technique called Routing, see:
What Was Stack Overflow Built With?
and Routing
Stack Overflow uses ASP.net MVC
MVC uses the URL + Query String to determine the content, so its not like a URL which points to a specific page, but more like a hierarchical path to the properties of some data to be displayed
E.G. https://stackoverflow.com/users/[Put User ID Here]/[Put User Name Here]
prompts the website to display a USER with an ID specified in the path ( in this case the user name is probably just for kicks ) as opposed to a specific page created just for that user.
I have seen this accomplished by simply creating a folder for every web page and then having each folder contain a Default.aspx document (Assuming Default.aspx is setup as a default document in IIS, which it is by default). Then you can navigate to any folder on the site without specifying the page (Default.aspx).
For the dynamic part, I have worked with CMS systems that do it this way and the Default.aspx page simply inherits from some master template and the CMS system utilizes the ASP.NET rendering enginge to dynamically complete the web page.
Using folders may be a little heavy with the site structure, but it is an easy way to eliminate the page names from the browser.
This is how I structure my website and avoid having to use page names... for example http://www.innovaapps.net/Blog simply brings up the default.aspx page without having to specify the page name.