ASP.NET: Path in place of URL arguments

Someone asked on Stack Overflow:

I’ve been taking URL arguments in ASP.NET like so:

www.mysite.com/thread.php?id=123

However, I’d like to use the cleaner method that you often see which looks like:

www.mysite.com/thread/123

How can I do this (get the arguments) in ASP.NET? What’s the usual procedure for setting up a system like this?

I posted the following answer, which was chosen as the accepted answer and received 1 upvote:

What that is called, is Url Rewriting. If you are using the ASP.NET-MVC Framework, you get this behavior by default, along with a design pattern that helps make developing it easier.

If you’re trying to shoehorn this onto an existing application, I recommend that you look into some url rewriting modules.

Notable comments

Nate (0 upvotes): In visual studio, a “website” is just a bunch of aspx files in a folder, in an “application” there is a .prj file that keeps track of what files are in the project.


Originally posted on Stack Overflow — 1 upvotes (accepted answer). Licensed under CC BY-SA.

Return muliple selectlist with one actionresult

Someone asked on Stack Overflow:

I’d like to display 2 SelectList in one View. So obviously, I can only use 1 ActionResult to render the view.

public ActionResult IndexStudents(Docent docent, int lessonid, int classid)
        {
            return View(new SelectList(docent.ReturnStudentsNormalAsString(lessonid, classid)));
            return View(new SelectList(docent.ReturnStudentsNoClassAsString(lessonid, classid)));            
        }

But of course, this does not work. How could I fix it? Maybe making use of a Dictionary?

I want my output look like this:

<div class="editor-field">
                     <%: Html.DropDownList("IndexStudentsNormal", 
                    Model as SelectList) %> 
 </div>
<div class="editor-field">
                     <%: Html.DropDownList("IndexStudentsNoClass", 
                    Model as SelectList) %> 
 </div>

So I’d like to use 2 models, one for each selectlist… one with normal students and one with students who are not subscribed for lessons.

How could I do that?

I posted the following answer, which was chosen as the accepted answer:

You need to define a model with two SelectLists:

// new class in your project
public class SelectListModel
{
    public SelectList SL1 { get; set; }
    public SelectList SL2 { get; set; }
}


// updated version of your ActionResult    
public ActionResult IndexStudents(Docent docent, int lessonid, int classid)
{
    var myslm = new SelectListModel 
    {
        SL1 = new SelectList(docent.ReturnStudentsNormalAsString(lessonid, classid),
        SL2 = new SelectList(docent.ReturnStudentsNoClassAsString(lessonid, classid)
    };
    return View(myslm);
}


// updated view code
<div class="editor-field">
    <%: Html.DropDownList("IndexStudentsNormal", Model.SL1 as SelectList) %>  
</div>
<div class="editor-field">
    <%: Html.DropDownList("IndexStudentsNoClass", Model.SL2 as SelectList) %>
</div>

Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.

C# WPF horizontal scrollbar for ScrollViewer RepeatButtons only on either side of contents

Someone asked on Stack Overflow:

Is there a way to get a scroll viewer with the RepeatButtons only and to force the buttons to the edge of the contents?

I want it to look like this:

  +---+-------------------------------------------------------------+---+
  |   |                                                             |   |
  | < | Contents here...............................................| > |
  |   |                                                             |   |
  +---+-------------------------------------------------------------+---+

Where the middle is the content of the ScrollViewer, and the left and right are RepeatButtons which will scroll the contents.

I was thinking I could either use a custom ScrollBar (but I don’t know much about this or how to make the buttons go outside the content), or I could just use RepeatButtons and connect their click to the ScrollViewer. Which way (if either) would be better/easier?

I posted the following answer, which was chosen as the accepted answer:

I see no reason you cannot use a ScrollViewer. Configure the event handlers of your two arrows (left/right) to minipulate ScrollToHorizontalOffset() and ScrollToVerticalOffset.


Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.

Tips and Suggestion on how to create a quiz using php and jQuery

Someone asked on Stack Overflow:

I do want to create a Quiz like on this site

Quiz

How can I done this using php and jQuery? or is there other way to do this not using flash

I do got a idea from this and my problem is how to implement the timer with this

Creating a Quiz with jQuery

answer and made by @Fatih

I posted the following answer, which was chosen as the accepted answer and received 3 upvotes:

Apparently I don’t know my router bits; however, making a quiz can be really easy to build (hard-coded) or really hard to build (database-driven). The first is difficult to change later on while the second is quite easy.

It really depends what you want to do, both are quite doable with php and jQuery.

  1. I would setup a database of questions, answers, and user-responses.
  2. Then I’d createa a few php pages, one for the user to view /quiz.php and one for my jQuery to post data to /ajaxhelp.php (accessed by $.post())
  3. ajaxhelp.php would return JSON data based on the post paramaters. Mabye a question + 4 answers for “nextQuestion” then the jQuery would generate the form with a few radio boxes for each answer
  4. The user picks their answer, and then you $.post() it back; ahaxhelp.php checks the database to see if that was marked as the correct answer, and returns the result.
  5. jQuery gets the “nextQuestion” and makes a new form
  6. Display summary of results

edit

After your comment about static data, this simple html page should get you started:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script>

        <script type="text/javascript">
            var q1wa = 
            { 
                Question: 'Question One Text', 
                Answers: 
                [ 
                    { AText: 'Answer1 Text', RightAnswer: true },
                    { AText: 'Answer2 Text', RightAnswer: false },
                    { AText: 'Answer3 Text', RightAnswer: false }
                ]
            };

            $(document).ready(function () {
                $('#question').html(q1wa.Question);
                for(var i = 0; i < q1wa.Answers.length; i++) {
                    $('#answers').append(q1wa.Answers[i].AText + "<br />");
                }

            });
    </script>
    </head>
    <body>
        <div id="question"></div>
        <div id="answers"></div>
    </body> 
</html>

It should be noted, that with this method, your “correct” answer is visible to anyone who cares to do a View Source, but this is a good starting point. It would also not be hard to incorporate a php portion to keep the answer secret by doing answer validation server-side instead of client-side.


Originally posted on Stack Overflow — 3 upvotes (accepted answer). Licensed under CC BY-SA.

What is best way to create scrolling WORLD?

Someone asked on Stack Overflow:

In this game im trying to create, players are going to be able to go in all directions

I added one single image(1024x768 2d texture) as background, or terrain.

Now, when player moves around I want to display some stuff.

For example, lets say a lamp, when player moves enough, he will see lamp. if he goes back, lamp will disappear because it wont be anymore in screen

If Im unclear, think about mario. when you go further, coin-boxes will appear, if you go back they will disappear. but background will always stay same

I thought if I spawn ALL my sprites at screen, but in positions like 1599, 1422 it will be invisible because screen is only 1024x768, and when player moves, I will set place of that sprite to 1599-1,1422-1 and so. Is it a good way to do this ?

Are there better ways?

I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:

There are two ways you can achieve this result.

  1. Keep player and camera stationary, move everything else.
  2. Keep everything stationary except the player and the camera.

It sounds like you are trying to implement the first option. This is a fine solution, but it can become complicated quickly as the number of items grows. If you use a tile system, this can become much easier to manage. I recommend you look into using a tile engine of some sort. There are a lot of great tile map editors as well.

Some resources for using Tiles:

  • Tiled — Nice Map Editor
  • TiledLib — XNA Library for using Tiled Maps

Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.

What does this code do in c# and what is it&#39;s purpose?

Someone asked on Stack Overflow:

 public class A {
    public Par mParams;
    public Par Parameters {
        get { return mParams; }
        set { mParams = value; }
    }
}

I am new to c#

What is public Par Parameters? This seems neither a class or a function. Confused here.

I posted the following answer, which was chosen as the accepted answer and received 9 upvotes:

Think of it like a public Par getParameters() and public void setX(Par p) method in Java. So, it is closest to a “function” but it is actually called Property. You can use it like this:

A myObject = new A();
a.Parameters = new Par(...);

This is a property which is backed by a public field, in this case, it is somewhat redundant, mParms should be declared as protected or private.

I recommend that you review this MSDN Programming Guide on Properties. It explains quite well, how they work and what they’re used for.


Originally posted on Stack Overflow — 9 upvotes (accepted answer). Licensed under CC BY-SA.

What is involved in creating a real-time multiplayer platformer game?

Someone asked on Game Development:

I’m creating a platformer game that has a “co-operative” feature which I’d like to work over networks / the internet.

Now I’ve read up on network game programming including articles like What every programmer needs to know about game networking and so I understand the difference between techniques like Peer-to-Peer lockstep and Server-Client prediction architectures:

  • I’ve concluded that for any real-time game that is going to be played over the internet, Peer-to-Peer lockstep simply isn’t an option.
  • I’m also concerned that even for a platformer a simple client-server architecture (without some sort of client prediction) would result in degraded gameplay due to the delay between action and reaction caused by a round-trip to a server. (Having said that I want to eliminate the need for a central server, and so only one of the players, the client, will actually experience this lag).

This leaves client prediction, but even for a simple game like a platformer this still sounds pretty complex.

How would I go about creating a working client predictive system for a multiplayer platformer game?

I posted the following answer, which was chosen as the accepted answer and received 6 upvotes:

I don’t think that half of your code base will turn into network code if you decide to implement a feature such as this.

In my opinion, the most simple way to do this, is to setup a “central” server (even if that means that one player “hosts” the game and then connects to his own server) that accepts all user input as fast as possible, and sends it back out to each client.

On the client, you implement this no differently than if you were doing a co-op game for two players locally, except you read P1 from keyboard, and P2 from network.

You’ll need to have the server send out a full game state every once in a while, and both clients can either snap to the new authoratitave state from the server, or they can slide into the new state (over a few seconds). Unless you have horrible packet loss or tons of clients per server, this approach should suffice for the situation you outline.

Notable comments

Nate (1 upvotes): No, I’m suggesting that you send full game states occasionally, so the client can make sure that it is not too far off.


Originally posted on Game Development — 6 upvotes (accepted answer). Licensed under CC BY-SA.

Duplicating a website in IIS 7

Someone asked on Server Fault:

I’ve set up an integration website in IIS 7 on Windows Server 2008 r2.

Now, I’d like to create copies of this site with different bindings and physical paths so that each developer can work on his own copy of the site.

On a previous project, I simply created a new site in IIS and then manually recreated all the necessary configuration changes. But this project’s site has some fairly complicated configuration, and I’d rather not have to go through all that a second (let alone third or fourth!) time.

Is there a way to duplicate a site in IIS 7?

I posted the following answer, which was chosen as the accepted answer and received 1 upvote:

Could IIS Export be the tool you’re looking for?

Additionally, this StackOverflow post may be useful: https://stackoverflow.com/questions/841547/how-can-i-duplicate-a-websites-settings-in-iis7

Effectivly, all settings are stored in the web.config file, so you should be able to simply duplicate that after you have used the IIS GUI to make your configuration changes.


Originally posted on Server Fault — 1 upvotes (accepted answer). Licensed under CC BY-SA.

moving emails from google apps to microsoft exchange 2010

Someone asked on Server Fault:

We have our emails hosted with Google Apps at the moment and would like to migrate to an in-house solution with Microsoft Exchange 2010 server. How would i go about migrating all the emails from Google Apps to MS Exchange 2010?

Is there an option in Exchange to do so?

I posted the following answer, which was chosen as the accepted answer and received 1 upvote:

I don’t know of any automated tool; however, if you connect Outlook to the new Exchange account and the Google Apps account through IMAP, you can drag/drop emails and folders from the old Google Apps to the new Exchange accounts.

You could probably write an Outlook Macro to do this automatically, but I have not delt with VSTO or Outlook Macros, so thats just speculation.


Originally posted on Server Fault — 1 upvotes (accepted answer). Licensed under CC BY-SA.

windows automatic copy / move / delete files

Someone asked on Server Fault:

Is there any utility / software which could periodically / scheduled copy / move / delete files over network or with hard drives?

I posted the following answer, which was chosen as the accepted answer and received 4 upvotes:

Windows Task Scheduler will allow you to setup very complex (or very basic) schedules to run scripts.

robocopy is a great tool which can do all sorts of file minipulations, it works well with UNC paths, copy and xcopy both require pushd and popd to map your shares to the Z:\ drive (typically not a problem, and xcopy may even do this automatically) but I find the flexibility and power of robocopy to be more useful. It is on Windows Vista / Server 2008 + by default, and a free download from microsoft for XP and Server 2003.

You can use powershell or windows command shell to call robocopy and make your copy / move / delete operations.

For example, save the following to a file called backup.bat :

robocopy \\server1\shareA\ \\server2\backups\shareA\ /MIR

This will copy everything on server1 that is in shareA to the backups share on server2 the /MIR switch says to mirror the changes, so deletes in shareA are also deleted in backups\shareA

Then, open the Task Scheduler, and configure it to run backup.bat file every night (or whatever schedule you need to make these copy / move / delete.


Originally posted on Server Fault — 4 upvotes (accepted answer). Licensed under CC BY-SA.

signed letter b

Dad. Geek. Gamer. Software developer. Cloud user. Old Car enthusiast.  Blogger.


Top Posts


profile for Nate on Stack Exchange, a network of free, community-driven Q&A sites
a proud member of the blue team of 512KB club
Thoughts, opinions, and ideas shared here are my own. © 2026 Nate Bross.