Category Archives: Controller

[RESOLVED] Url Routing in .net 4.0 and 3.5

Hello,

    I am trying to implement Url routing in 4.0 by following example http://www.dotnetspark.com/kb/2369-step-by-step-tutorial-on-url-routing-asp-net.aspx

Works fine..

Now the scenario is that i have gridview with object datasource which accepts  "Name" as query string.

<asp:gridview ID="Gridview1" runat="server" DataSourceID="ObjectDataSource1"></asp:gridview>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
            OldValuesParameterFormatString="original_{0}" SelectMethod="Hello"
            TypeName="WebApplication2.Class.MethodsTest">
            <SelectParameters>
                <asp:QueryStringParameter Name="value" QueryStringField="Name" Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>

i tried this code. But i couldn't get the value in QueryString Field??

How to handle in this situation??

+

How to implement (the link example in net 3.5)??? because i don't  "

routes.MapPageRoute


" attribute in  3.5. i have few existing application in 3.5 so thought of implementing there too.


Please guide me..This example in Link looks very easy and simple to handle


Thanks....

if your getting the value parameter from a pageroute you cant use querystring you should use a Route Parameter something like this.

<asp:RouteParameter RouteKey="Name" Name="value" Type="String" />

here you have another example how to do it... http://weblogs.asp.net/hajan/archive/2010/10/15/url-routing-in-asp-net-4-0-web-forms.aspx

In his example he is showing a codebehind example of how to access the route but in my example show you how to use it...

Hope it helps....
 

So you mean to say that i can't use querystring for passing value to objectsource???

How to pass the value objectsource then???

In your link you have shown it in asp.net 3.5 sp1. right??

But how to pass value on click of the Button? like he has shown in the example (mine link).


because in my scenario i have to pass value through querystring in many places...so before i implement this feature i need to know how to access the value in pass it in objectdatasource and i don't want to use code behind.

i just checked on net http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx

Is the

<asp:routeparameter name="category" RouteKey="category" />

not available for 3.5 sp1 in webforms???

Thanks.




Im not sure if it works in 3.5 I upgraded all my apps to 4.0 when implementing routing. 

If you use url routing the routeparameter replaces querystring. the querystring fetches the parameter after the questionmark (?) in the url and when using routing you dont have it. 

 

i could see few example with routing stuff in asp.net 3.5 but i am not able to get  <asp:routeparameter in my html.



indeed this is why I choose to wait with moving from URL rewrite to URL routing until I moved to ASP.NET 4.0 even finding answers for URL Routing 4.0 is difficult if your not working with MVC and want some info covering more than the basic's

this works with ASP.NET 4.0 but if the <asp:routeparameter is not supported in asp.net 3.5 I can only see that you have to declare it in codebehind if you want it to work with you SqlDataSource.

 

ok i made one small application in 4.0 now and implemented Url routing in that and hosted in IIS in my machine (win 7).

but i get an error

HTTP Error 404.0 - Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

now what could be the reason...when i am running with my visual studio then it works fine but when i hosted in IIS then i landed in above problem.

code i use.

protected void Application_Start(object sender, EventArgs e)
        {
            CustomRouteTable(RouteTable.Routes);
        }


   void CustomRouteTable(RouteCollection routes)
        {
           

            routes.MapPageRoute("Telugu", "Movie/Telugu", "~/Telugu/Telugu.aspx");
        }

and in my default.aspx i kept a button on click of the button i wrote:

 protected void btnTelugu_Click(object sender, ImageClickEventArgs e)
        {
            Response.RedirectToRoute("Telugu");
        }


now where am i going wrong????

please guide me...


Hi,

abhishek0410

HTTP Error 404.0 - Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

 

It seems that IIS can not handle the UrlRoute when you enter the route url in browser.

I think you need to check the .NET framework version of the web site application pool. Url Route module need .NET 3.5 or upon.

Open the IIS manager and check it.

How to check the .NET version on IIS7:

http://www.west-wind.com/weblog/posts/289139.aspx

http://technet.microsoft.com/en-us/library/cc754523(WS.10).aspx

Or add the UrlRoutingModule in web.config:

Check this link:

http://msdn.microsoft.com/en-us/library/cc668202(v=vs.90).aspx

Hope this can help you.

Well do you have a file with the path ~/telugu/telugu.aspx because that is what you pointing at!

my guess would be that not...

 routes.MapPageRoute("Telugu", _ //routename

"Movie/Telugu", _  // you have hardcoded a virtual path and it is not expecting any paramenters parameter should be within {}

"~/Telugu/Telugu.aspx"); // this is the physical path...

--------------------------------------

let say you hav a file Movie.aspx in your root folder and you want to have a url that is movie / title .aspx it the route you should register is like this

routes.MapPageRoute("MovieRoute""Movie/{title}""~/Movie.aspx");

and then for the url to redirect correctly with a given parameter it should be something like this  

RedirectToAction("title", "Movie"); // Action, Controller
RedirectToRoute("MovieRoute"); // Route name or like this if it is to a route without a parameter

hope it helped a little

[RESOLVED] URL Manipulation

I have an c# web application with URL being;

http://dmhtest/UI/index.aspx

How do I go about making the URL just being the following;

http://dmhtest/UI

?? 

In your IIS console, add default document (index.aspx) for your site. 

Also, you can add 301 redirect in your Global.asax file (BeginRequest event, there you'd check if request is for

index.aspx and do 301 redirect to http://dmhtest/UI)

 

Hope this helps.

This is done using ASP.net MVC framework. If you use .aspx extensions, you are basically pointing to a file in your folder structure. 

Using MVC framework, you are pointing to a controller action which then routes it to the appropriate page.

See this for detailed information.

http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

[RESOLVED] how to use RouteUrl expressions in asp.net 3.5 (VS 2008)

 

 

 

 

 

 


Hello People,

below code run perfect on .net 4.0 (VS 2010), but not in .net 3.5 (VS 2008), i believe not supported in VS 2008, so whats the alternate/easiest way..please help?

========================================================================================================

<%

 

@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication1.WebUserControl1"

%>

<

 

 

ul id="menu">

 

 

<li><asp:HyperLink ID="hypHome" runat="server" NavigateUrl="<%$RouteUrl:routename=default,controller=home,action=index%>">Home</asp:HyperLink></li>

 

 

 

<li> <asp:HyperLink ID="hypProducts" runat="server" NavigateUrl="<%$RouteUrl:routename=default,controller=products,action=index%>">Products</asp:HyperLink></li

>

 

 

<li><asp:HyperLink ID="hypReport" runat="server" NavigateUrl="<%$RouteUrl:routename=ReportRoute,reportname=products%>">Product Report</asp:HyperLink></li>

 

 

<li><asp:HyperLink ID="hypHelp" runat="server" NavigateUrl="<%$RouteUrl:routename=default,controller=home,action=help%>">Help</asp:HyperLink></li

>

</

 

 

ul

>

<%= Html.ActionLink("NameToDisplay", "Action","ControllerName") %>

Thnx Ravi, but i need to use below menu control in web master page, hence Html.ActionLink will not work.

I want to convert below code

 

<ul id="menu">    <li>        <%=Html.ActionLink("Home", "Index", "Home") %></li>    <li>        <%=Html.ActionLink("Products", "Index", "Products") %></li>    <li>        <%=Html.ActionLink("Help", "Help", "Home") %></li></ul>

 

to

 

<ul id="menu">    <li>        <asp:HyperLink ID="hypHome" runat="server" NavigateUrl="<%$RouteUrl:routename=default,controller=home,action=index%>">Home</asp:HyperLink></li>    <li>        <asp:HyperLink ID="hypProducts" runat="server" NavigateUrl="<%$RouteUrl:routename=default,controller=products,action=index%>">Products</asp:HyperLink></li>    <li>        <asp:HyperLink ID="hypReport" runat="server" NavigateUrl="<%$RouteUrl:routename=ReportRoute,reportname=products%>">Product Report</asp:HyperLink></li>    <li>        <asp:HyperLink ID="hypHelp" runat="server" NavigateUrl="<%$RouteUrl:routename=default,controller=home,action=help%>">Help</asp:HyperLink></li></ul>

 

but it not works with vs 2008(.net 3.5)...what need to do..please help

hence Html.ActionLink will not work.

I am using it in master page it is working properly are u getting some error

I did'nt get your point.Could explain me more about your scenario

please check below article..here Menu code works perfect in VS 2010, but noe in VS 2008.

http://weblogs.asp.net/rajbk/archive/2010/05/11/running-asp-net-webforms-and-asp-net-mvc-side-by-side.aspx

 

I have a vague feeling that routing changed between 3.5 and 4, which is why it works in one and not the other. You might want to check the System.Web.Routing assembly to see what those changes are.

[RESOLVED] Video in asp

Hello,

i have an ip camera that expose video in two formats, m-jpeg and RTP/RTSP.I want to show this video in an asp page (i am using c# , asp.net 3.5 and visual studio 2008).What is the best way to show the video.Can someone help me with that?Can i use windows media player component?

Thank you

 

<form id="form1" runat="server">
        <object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" id="player" width="320"
            height="260">
            <param name="url" value="c:\\globe.avi" />
            <param name="src" value="c:\\globe.avi" />
            <param name="showcontrols" value="true" />
            <param name="autostart" value="true" />
            <!--[if !IE]>-->
            <object type="video/x-ms-wmv" data="1.mpg" width="320" height="260">
                <param name="src" value="http://myserver:9090\videos\globe.avi" />
                <param name="autostart" value="true" />
                <param name="controller" value="true" />
            </object>
            <!--<![endif]-->
        </object>
    </form>

 

Also Please check.

Display Videos in ASP.NET 2.0

http://forums.asp.net/t/1148219.aspx/1?display+video

http://forums.asp.net/t/1483237.aspx/1?Video+display

Thank you for your reply but none of the methods posted help me with my problem.Media player does not recognise the m-jpeg format.

Nothing to do with .NET at server side if you you m-jpeg.

Client machine should have m-jpeg codec for Media Player to play them.

I suggest convert your video files to one of the mdia player formates like avi.

Thank you for your answer. Is there any way to convert the video in other format on the fly (server side) and then serve it to client?

 

Yup you can find the API. but I do not suggest them as it costs user experiance. because conversion takes good amout of time.

will your all videos file be converted to AVI at one shot using a tool, and then map AVI files in your web app.

[RESOLVED] My list crashes my browser, need alternative solution ideas

Hello,

In my website I have a dropdownlist filled with the countries of the world. Once you select a country you will be provided with a <ul>list of the <li>cities in that selected country. Great! Appart from the fact that if your computer doesn't have 4GB RAM or more your browser will crash at countries like France and Italy because they have just got too many cities. It is split into the letters tho, having A listing only the cities with a name that begins with A. This is how that looks for Sweden - A:

It's built like this, the controller (using mvc 3 btw) is the one who's retrieving all the data from the database and pushing that into the view, it's the jquery that sorts things out making it look all pretty. 

My question is, as a sort of beginner to mvc, is it the complete number of cities that crashes my browser or is it the number of cities displayed that crashes it? More specifically, do I need to alter my jQuery or my Controller? 

Either way, jQuery or Controller, I could really use some feedback, alternatives, ideas and such as to how I should do this the best way. I have tried a truncate on the <ul> but this has not worked, I guess because my list is also generated from the database (using textarea template filled up by the jQuery). I was trying out a pagination (but didn't get too far with that). Actually as I was writing this post I realised that none of those things would probably make a difference, I assume (from my limited knowledge) that its the controller getting all the cities at once which ruins things, and a pagination wont fix that. I was considering making each letter a new call to the controller, but that would create an unattractive loading time for the end user. 

What's your opinion, what do you think I should do?

Hi Jennica,

Don't get all the cities of a particular contry based on the selection from dropdown. Only get the first letter cities. i.e. cities start with "A"

So let's cosider you choose France from dropdown and populate all the cities from France starting with "A"

Then after you will have all your logic related "B","C" and so on.

One more thing, for this kind of large data. Implement indexing on column on which where condition is frequently calling.

Like in this case I suppose you are passing CountryId to get all the cities. So you can implement indexing on countryid.

So data filtering will be high.

Hope it helps. 

 

Hi Lyra, 

Thank you for your answer. 

Yes, i've realised that the best way to do it is to just make a request depending on which letter is chosen. I will do that. 

Lyra Belaqua

One more thing, for this kind of large data. Implement indexing on column on which where condition is frequently calling.

Like in this case I suppose you are passing CountryId to get all the cities. So you can implement indexing on countryid.

So data filtering will be high.

Will you please explain what you mean by indexing column? I am, as you suggest, using the CountryId to find my cities which stands as a value in the ddl, that one is retrieved, sent to my controller which sends me back my cities. What is it that you suggest I change?

Thanks!
Jen 

Indexing is a SQL mechanism to retrieve data at faster speed.

For more details you can follow this.

http://www.mssqltips.com/tip.asp?tip=1206

http://blog.sqlauthority.com/2007/04/23/sql-server-understanding-new-index-type-of-sql-server-2005-included-column-index-along-with-clustered-index-and-non-clustered-index/

So apply index on countryId in City table.

I suppose city table contains CityId, CityName, CountryId and you are applying some query like

select CityName,CityId FROm City WHERE CountryID = CountryID

As your search is dependent on countryid, indexing on that column will boost performance.

Hope it helps.

 

 

 

Hi Jannica,

You could also try using a paged GridView instead of a dropdownlist. I can see your problem is memory related, not actually a performance issue. What I mean is, the browser is rendering too much data on the screen and sometimes it just cant handle it. WIth a paged GridView, you could show the data from little to little, like, for example, 20 items per page. However, you would have to change the control in your page. Altought, your binding would remain the same.

Best regards

Lyra Belaqua

As your search is dependent on countryid, indexing on that column will boost performance.

This is great Lyra, Thank you!