Using ASP.NET 4.0, IIS 7.5.
I have a website engine, I have just implemented a way for this to tell if it's being loaded on mobile and instead of loading Controls\MyControl.ascx it loads Mobile\Controls\MyControl.ascx. This works well for my controls and also my MasterPage.Master file.
What I can't figure out however is how I can do the same with Default.aspx. This needs to be done on the fly programatically as I need to be able to check if it's mobile version. I was thinking of doing something on a pre-init event in globals but not sure if that's the best way.
Note: I don't want to use inline code on Default.aspx and just display different content base on my Mobile flag as my scenario goes one step further by basing the file on customer as well and this would mean having one huge Default.aspx for all customers which wouldn't be manageable.
Changing the default document on the fly is not possible in any practical sense.
Writing to the web.config on the fly to load a mobile version of a default page is quite frankly terrible and not an answer to the true context of your issue. I would feel irresponsible as a developer if I even proposed this as an answer to loading a mobile version of a default page.
I was trying to help you solve your problem and not just answer the base question in the title. As we all know, changing the web.config will restart your application and would not serve as a true solution, as you could not do this and achieve any kind of performance.
Here is the BEST alternative (IMHO) to dealing with mobile browsers.
http://51degrees.codeplex.com/
HTH!
For anyone else looking at this I have found a solution but I am not sure I will implement it as I don't like the idea of updating the web.config file at run time. Using the Microsoft.Web.Administration namespace you can update the server.webServer -> defaultDocument section programmatically. Doing this allows you to change the path to default.aspx and it will load based on the variables you set.
This link should provide more information: http://blogs.msdn.com/b/saurabh_singh/archive/2007/11/24/accessing-iis-7-0-features-programmatically-from-configuration-file-s-c.aspx
Also, the Microsoft.Web.Administration dll isn't available directly in VS so you need to add it from %windir%\syswow64\inetsrv (64bit version).
Related
Following this answer, I've enabled serving JavaScript and CSS from my Views folder which is helping my project's organization. Unfortunately, while I'm developing, I find I have to disable my browser cache in order to see my changes. I'd like to be able to develop without keeping DevTools open just to disable the cache.
I figure my issue is the System.Web.StaticFileHandler serving up the files in such a way that the browser caches them. I've tried using System.Web.Handlers.TransferRequestHandler like this answer suggests, but then I get 500 Server Errors instead.
Is my understanding of the problem correct? How can I resolve my issue?
Note: Not that it's relevant, but I intend to add a config transform to switch back to the static handler for releases.
I'm currently working on a Microsft Word Application-Level Add-in using C#. My application contains an app.config file. In this file I save user-settings (userSettings-Section) and some data defined by a custom ConfigurationSection. The data stored inside of custom ConfigurationSection is also user-specific.
I access the user-settings as follows:
Properties.Settings.Default.MyUserSetting
The custom ConfigurationSection I'm using like:
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
.GetSection("MyCustomConfigurationSection")
My questions are:
Do I even use the app.config the "correct" way? (I know that there is probably not only one correct way, but is "my way" one of these?)
Which ConfigurationUserLevel does Propeties.Settings.Default use? Is there a way of setting/changing it?
And Most importantly: Is there a way to automatically keep the user-specific settings during an upgrade of my application, but at the same time add newly created settings?
I deploy my Add-in using an installer built with WiX. At the moment I use CustomActions, which manually insert code for each added/removed/changed setting. But I was wondering whether there is a built-in way of doing this.
I did some researches the whole day now and I think I can answer my questions for myself:
Q: Which ConfigurationUserLevel does Propeties.Settings.Default use? Is there a way of setting/changing it?
A: It seems that Propeties.Settings.Default use ConfigurationUserLevel.PerUserRoamingAndLocal, what sounds logical as they only contain userSettings... I don't know whether it is possible to change it, but for me it is not necessary.
Q: Is there a way to automatically keep the user-specific settings during an upgrade of my application, but at the same time add newly created settings?
A: I found out that there is an Upgrade()-Method in Settings which should take care of copying user settings between an older version of the product and the new one. For more information see http://ngpixel.com/2011/05/05/c-keep-user-settings-between-versions/. I must confess that I haven't had occasion to test it, since I have no permissions to build the installer, but I will rely on it. I will come back to this post after I tested my solution.
Furthermore I am not using a custom ConfigurationSection any more. Instead I derive from System.Configuration.ApplicationSettingsBase, which means that I am able to handle the custom data exactly like the Properties.Settings, including the Upgrade()-Method. See this post for more information about how to use it.
Hope this helps somebody.
I have been some time using asp.net charts, even it was hard to config for asp 3.5 and to make it work, I have been able to move along with all my project but I'm facing something that I have no idea how to solve.
This project works perfectly on my develop enviroment, but when i deployed it on the server, the only page with charts on it appeared like this:
I assume its cause of the charts because its the only thing that really have given me problems and its the only thing that its exclusively on this page but i have no idea how this happens, it only happens on the server with Plesk.
Tried to upload on debug instead of release but the result is the same. Searched overall but never found anything like this.
My Answer may not give you the exact solution. But it may give you an idea's.
Below are my Ideas:
Make Sure you have included all the files into your solution when you do the Build.
Make Sure you have all dependency of Asp.Net Charts in Server.
Check you browser Console and Browser Network. Press F12 in your and check. You can get to know the Exact problem if any issue in loading prob / dependency files.
Double check your server configurations for the charts. And compare your local and server configs.
Do the Deployment in your machine itself and check one round.
Background info: 2 semesters of C#(WinForms), plenty of HTML/CSS skill, brand new to asp.net.
I'm building a site for a friend who's a photographer. It's just a gallery site, but he'd like to be able to update the galleries himself and he's not tech savvy in the least. So I'm using the following approach to the problem:
Using ASP.NET 4 WebForms:
I'm using System.IO to get the names of the folders which represent the "Galleries" and populating a TreeView control for navigation.
When a "Gallery" is selected, I have code that builds a (HTML)list of the image files and populates an UpdatePanel with this list.
As this is all based on the folders/files, I'm building him an secure admin page to upload files to new or existing galleries(folders). He'll also be able to edit(move/delete) the existing files from there.
I got it all to work, which was a nice little victory, but I'm realizing this approach is not optimal, as none of the unique galleries are findable via search engine or even URL; the SEO value is nill; the browser back/forward buttons are useless...
Can you guys/gals recommend a better way to go about this?
Is there a way to modify what I've already done to optimize the project?
I'll gladly start over to do this right.
Thanks
Couple of suggestions, if you are doing this for fun - and want to learn something, consider using ASP.Net MVC instead. Both will work, but doing it with MVC will give you more up-to-date and marketable skills.
Second, unless you really want to write the whole thing from scratch, consider using a package to do most of what you want and then customize it.
Something like this would work quite well: http://www.galleryserverpro.com/ and is open source, free/cheap and well supported.
SInce you are new to asp.net, you can learn a lot by picking thru the open source code and seeing how other people with more experience have already solved the very same issues.
When a "Gallery" is selected, I have
code that builds a (HTML)list of the
image files and populates an
UpdatePanel with this list.
Well, most of your problem is sitting inside this sentence. get rid of the UpdatePanel. When you are making ajax request, you are not able to allow browser history. so SEO, back/forward nav. buttons are always issue with updatepanel.
http://ajaxhistory.com/
I need to create and add custom headers to an ASP.NET 2.0 application.
The case is simulation of an SSO-login in our dev/test environment.
When I try to add headers I run into the "Not supported on this platform."
error. BigJim has a nice post on the subject here:
http://bigjimindc.blogspot.com/2007/07/ms-kb928365-aspnet-requestheadersadd.html
The root of my problem lies in the fact that I need to simulate various
persons logging into my application. Not just adding static data in a
HttpModule. I need to take values from a couple of TextBoxes and transfer
information from these into custom headers and then re-direct the user. The
HttpModule stuff happens to early in the pipeline...
Does anyone now if there exsist a simple redirect/proxy solution that one
could use in a dev environment? Or have simple/beautiful way of doing it in code?
One method i have used before, though a long winded approach, is NUnitASP.
This is based on the NUnit framework but intended for ASP.NET UI Testing.
It basically starts a browser in memory, and is able to manipulate the content exactly like a user would.
Using this you could view your page, enter data into textboxes and submit pages.
Hopefully that can help you do the testing you require. I've used it to test load, and spider through sites of mine to gather data.
If you use IIS 7 you can set the Pipeline Mode to integrated
This Setting is found in the App-Pool Properties.
I could be wrong, but doesn't the Response.AddHeader() method still work? Although, I agree with Oscar that a formal testing solution like NUnitASP is a good idea. Although, NUnitASP is a little dated. I still use it for some of my projects just because it still does work; it just isn't as refined or as simple as WaTiN or similar projects.
The browser drops the header if you do a Response.AddHeader()...
The header must be added to the orginal Request...
why don't use ASP.NET forms authentication model?
you define your "private folders". if you attempt to acces to a private folder without login, you automatically are redirected to a your custom login page.
here's a couple of link:
http://support.microsoft.com/kb/301240
http://www.asp.net/learn/security/tutorial-02-cs.aspx