Writing my first VB.NET Class -


i trying make 2 variables available throughout site. parsing url in order retreive both of them.

this code on page works fine.

dim countrylanguage string countrylanguage = (request.servervariables("url")) dim langvar = (mid(countrylanguage, 2, 2)) dim countryvar = (mid(countrylanguage, 5, 2)) 

i have created class file code below. complilation error (bc30451: name 'request' not declared.).

public class url_parser      public shared function urlvars(byval langvar, byval countryvar) string         dim countrylanguage string         countrylanguage = (request.servervariables("url"))         dim langvar = (mid(countrylanguage, 2, 2))         dim countryvar = (mid(countrylanguage, 5, 2))     end function  end class 

thanks

you can use system.web.httpcontext.current.request request object current thread.

a better way country , language folders use request.url.segments.

public class url_parser     public shared function urllanguage() string         dim request = web.httpcontext.current.request         return request.url.segments(1).trimend("/"c)     end function      public shared function urlcountry() string         dim request = web.httpcontext.current.request         return request.url.segments(2).trimend("/"c)     end function end class 

access these static function way.

dim mylanguage = url_parser.urllanguage dim mycountry = url_parser.urlcountry 

in example, if url "/en/us/" then...

  • segment(0) "/"
  • segment(1) "en/"
  • segment(2) "us/"

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -